package com.eascs.bankAccount;

import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/bank/account")
public class BankAccountMgrRestController extends BaseRestController {
	@Autowired
	BankAccountService bankAccountService;

	@RequestMapping(value="/page/add")
	public HtmlRestResult add(){
		return  HtmlRestResult.popHtmlFragment("/bank/bank_account_add");
	}

	@RequestMapping(value = "/add")
	public BaseRestResult<String> bankAccountMgrAdd(BankAccountEntity bankAccount) {

		if(null != bankAccount) {
			BaseRestResult.info("参数为空，保存失败").andCloseActionDialog().andRefresh();
		}
		User user = UserHolder.getUser();
		bankAccount.setIsDel("0");
		bankAccount.setCreater(user.getCname());
		bankAccount.setCreateTime(new Date());
		bankAccount.setUpdateTime(new Date());
		if (bankAccountService.add(bankAccount)) {
			return BaseRestResult.info("保存成功").andCloseActionDialog().andRefresh();
		}
		return BaseRestResult.warn("保存失败").andCloseActionDialog().andRefresh();
	}

	@RequestMapping("/del")
	public BaseRestResult<String> bankAccountMgrDel(String id) {
		if (bankAccountService.del(id)) {
			return BaseRestResult.info("删除成功").andCloseActionDialog().andRefresh();
		}
		return BaseRestResult.warn("删除失败").andCloseActionDialog().andRefresh();
	}


}